package com.zsm.eblog.controller;

import com.zsm.eblog.pojo.ResponseResult;
import com.zsm.eblog.pojo.User;
import com.zsm.eblog.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Author : ZSM
 * Time :  2024/08/18
 */
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user) {
        User loginUser = userService.login(user);
        ResponseResult responseResult = new ResponseResult();
        if (loginUser == null || !loginUser.getPassword().equals(user.getPassword())) {
            responseResult.setStatus("not ok");
            responseResult.setMsg("登录失败");
            return responseResult;
        }
        responseResult.setStatus("ok");
        responseResult.setMsg("登录成功");
        responseResult.setData(loginUser);
        return responseResult;
    }
}
